from selenium import webdriver
wd = webdriver.Chrome(r'd:\chromedriver.exe')
wd.implicitly_wait(5)

wd.get('http://cdn1.python3.vip/files/selenium/test2.html')


# # 获取当前选中的元素
# element = wd.find_element_by_css_selector(
#   '#s_radio input[checked=checked]')
# print('当前选中的是: ' + element.get_attribute('value'))
#
# # 点选 小雷老师
# wd.find_element_by_css_selector(
#   '#s_radio input[value="小雷老师"]').click()
# 先把 已经选中的选项全部点击一下
# elements = wd.find_elements_by_css_selector(
#   '#s_checkbox input[checked="checked"]')
#
# for element in elements:
#     element.click()
#
# # 再点击 小雷老师
# wd.find_element_by_css_selector(
#   "#s_checkbox input[value='小雷老师']").click()

# # 导入Select类
# from selenium.webdriver.support.ui import Select
#
# # 创建Select对象
# select = Select(wd.find_element_by_id("ss_single"))
#
# # 通过 Select 对象选中小雷老师
# select.select_by_visible_text("小江老师")

# 导入Select类
from selenium.webdriver.support.ui import Select

# 创建Select对象
select = Select(wd.find_element_by_id("ss_multi"))

# 清除所有 已经选中 的选项
select.deselect_all()

# 选择小雷老师 和 小凯老师
select.select_by_visible_text("小江老师")
select.select_by_visible_text("小凯老师")